package com.kizuki.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;

// 两种空跑批设计
@Slf4j
@Configuration
@ConditionalOnProperty(prefix = "schedule", name = "enable", havingValue = "true")
@Async("TaskScheduler")
public class ScheduleConfig {

    private int times = 0;
    @Value("${schedule.enable1:false}")
    private boolean enable;

    @Scheduled(cron = "${corn}")
    public void logInfo1(){
        if (enable) {
            times++;
            log.info("logInfo1-跑批打印日志ing, times:{}", times);
        } else {
            log.info("logInfo1-空跑批");
        }
    }

    @Scheduled(cron = "${corn}")
    public void logInfo2() throws InterruptedException {
        times++;
        log.info("logInfo2-跑批打印日志ing, times:{}", times);
        Thread.sleep(30000);
    }

}
